<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane" action="">
                <!--<legend>搜索信息</legend>-->
                <div style="margin: 10px 10px 10px 10px">

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <!--<label class="layui-form-label">团队名称</label>-->
                            <div class="layui-input-inline">
                                <input type="text" name="title" autocomplete="off"  placeholder="按【团队名称】【手机号】搜索" class="layui-input soso">
                            </div>
                        </div>
                     <!--   <div class="layui-inline">
                            <label class="layui-form-label">手机号</label>
                            <div class="layui-input-inline">
                                <input type="text" onkeyup="this.value=this.value.replace(/[^0-9-]+/,'');" maxlength="11" name="phone" autocomplete="off" class="layui-input">
                            </div>
                        </div>-->
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>

                </div>
        </form>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加</button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="ldelete">查看团队</a>
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
        </script>

    </div>
</div>
{include file="public/footer" /}
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/admin/Member/teamInfo?action=ajax',
            method: 'post',
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data, //解析数据列表
                };
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print'],
            // defaultToolbar: '',
            cols: [[
                {type: 'checkbox'},
                {field: 'title', title: '团队名称', sort: true},
                {field: 'team_num', title: '团队人数', sort: true},
                {field: 'income', title: '团队总收益', sort: true},
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'line'

        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    title: data.field.title
                }
            }, 'data');

            return false;
        });


        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {
                var checkStatus = table.checkStatus('currentTableId'),
                    data = checkStatus.data;
                if(data==''||data==undefined){
                    layer.msg('请选择团队');
                    return false;
                }
                var NEWJSON = [];
                var teamHidden = [];
                layui.each(data, function (index, item) {
                    NEWJSON.push(item.title)
                    teamHidden.push(item.id)
                })
                let pteam=parent.$("#team"+"{$id}").val();
                if(pteam==''||pteam==undefined){
                    pteam=NEWJSON.join(",")
                }else{
                    pteam+=','+NEWJSON.join(",")
                }
                let pteamhidden=parent.$("#teamHidden"+"{$id}").val();
                if(pteamhidden==''||pteamhidden==undefined){
                    pteamhidden=teamHidden.join(",")
                }else{
                    pteamhidden+=','+teamHidden.join(",")
                }
                parent.$("#team"+"{$id}").val(pteam);
                parent.$("#teamHidden"+"{$id}").val(pteamhidden);
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);//关闭当前页
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {

        });
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            var id = obj.data.id;
            var memberCode = obj.data.member_code;
            if (obj.event === 'edit') {

                var index = layer.open({
                    title: '编辑',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: "/admin/team/write?id=" + id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'look') {
                //触发事件  查看内容
                var index = layer.open({
                    title: '领导人信息',
                    type: 2,
                    area: ['100%', '100%'],
                    fixed: false, //不固定
                    shade: 0.5,
                    shadeClose: true,
                    content: '/admin/member/write?code='+ memberCode,
                });
            } else if (obj.event === 'ldelete') {
                //触发事件  查看这个团队的所有玩家
                var index = layer.open({
                    title: '我的团队',
                    type: 2,
                    area: ['100%', '100%'],
                    fixed: false, //不固定
                    shade: 0.5,
                    shadeClose: true,
                    content: '/admin/member/index?mark=team&teamId=' + id,
                });
            }
        });


    });
</script>

</body>
</html>